package com.ahdy.service.impl;

import com.ahdy.entity.Medication;
import com.ahdy.mapper.MedicationMapper;
import com.ahdy.service.MedicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 药物信息服务实现类
 */
@Service
public class MedicationServiceImpl implements MedicationService {

    @Autowired
    private MedicationMapper medicationMapper;

    @Override
    @Transactional
    public Integer addMedication(Medication medication) {
        medicationMapper.insert(medication);
        return medication.getId();
    }

    @Override
    @Transactional
    public int updateMedication(Medication medication) {
        return medicationMapper.update(medication);
    }

    @Override
    @Transactional
    public int deleteMedication(Integer id) {
        return medicationMapper.deleteById(id);
    }

    @Override
    public Medication getMedicationById(Integer id) {
        return medicationMapper.findById(id);
    }

    @Override
    public List<Medication> getAllMedications() {
        return medicationMapper.findAll();
    }

    @Override
    public List<Medication> getMedicationsByNameLike(String name) {
        return medicationMapper.findByNameLike(name);
    }

    @Override
    public List<Medication> getMedicationsByType(Medication.MedicationType type) {
        return medicationMapper.findByType(type);
    }

    @Override
    public List<Medication> getMedicationsByManufacturerLike(String manufacturer) {
        return medicationMapper.findByManufacturerLike(manufacturer);
    }

    @Override
    public List<Map<String, Object>> getMedicationUsageStatistics() {
        return medicationMapper.getMedicationUsageStatistics();
    }
}